

using System;
using System.Collections.Generic;
using System.Text;

using JTC.MiniCommerce.Core.Serialization;

namespace JTC.MiniCommerce.Store.Services.CouponService {
  public class CouponService {
  
    #region Methods
    
    #region Public

    /// <summary>
    /// Applies the coupon.
    /// </summary>
    /// <param name="couponCode">The coupon code.</param>
    /// <param name="order">The order.</param>
    public void ApplyCoupon (string couponCode, Order order) {
      Coupon coupon = new Coupon(Coupon.Columns.CouponCode, couponCode);
      if(coupon.CouponId > 0) {
        if(coupon.ExpirationDate > DateTime.UtcNow) {
          ICouponProvider couponProvider = new Serializer().DeserializeObject(coupon.ValueX, coupon.Type) as ICouponProvider;
          couponProvider.ApplyCoupon(order);
        }
      }
    }
    
    #endregion
    
    #endregion
    
  }
}
